//
//  ViewController.m
//  ColoriOS13
//
//  Created by 王杰 on 2019/9/27.
//  Copyright © 2019 wangjie. All rights reserved.


#import "ViewController.h"

@interface ViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong)UITableView * tableView;
@property (nonatomic,strong)NSMutableArray * tableViewArray;
@property (nonatomic,strong)NSMutableArray * tableViewColorArray;
@property (nonatomic,strong)NSArray * headArray;
@property (nonatomic,strong)NSArray * foregrounds;
@property (nonatomic,strong)NSArray <UIColor *>* foregroundColors;
@property (nonatomic,strong)NSArray * backgrounds;
@property (nonatomic,strong)NSArray <UIColor *>* backgroundColors;
// Fill colors
@property (nonatomic,strong)NSArray * fills;
@property (nonatomic,strong)NSArray <UIColor *>* fillColors;

@property (nonatomic,strong)NSArray * systems;
@property (nonatomic,strong)NSArray <UIColor *>* systemColors;

@end



@implementation ViewController

- (NSMutableArray *)tableViewArray{
    if (!_tableViewArray) {
        _tableViewArray = [NSMutableArray array];
    }
    return _tableViewArray;
}


- (NSMutableArray *)tableViewColorArray{
    if (!_tableViewColorArray) {
        _tableViewColorArray = [NSMutableArray array];
    }
    return _tableViewColorArray;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.headArray = @[@"Foreground colors 前景",
                       @"Background colors 背景",
                       @"Fill colors 填充",
                       @"System colors 系统"];
    self.foregrounds = @[@"labelColor",
                         @"secondaryLabelColor",
                         @"tertiaryLabelColor",
                         @"quaternaryLabelColor",
                         @"linkColor",
                         @"placeholderTextColor",
                         @"separatorColor",
                         @"opaqueSeparatorColor"];
    self.foregroundColors = @[UIColor.labelColor,
                              UIColor.secondaryLabelColor,
                              UIColor.tertiaryLabelColor,
                              UIColor.quaternaryLabelColor,
                              UIColor.linkColor,
                              UIColor.placeholderTextColor,
                              UIColor.separatorColor,
                              UIColor.opaqueSeparatorColor];
    
    // Background colors
    self.backgrounds = @[@"systemBackgroundColor",
                         @"secondarySystemBackgroundColor",
                         @"tertiarySystemBackgroundColor",
                         @"systemGroupedBackgroundColor",
                         @"secondarySystemGroupedBackgroundColor",
                         @"tertiarySystemGroupedBackgroundColor"];
    self.backgroundColors = @[UIColor.systemBackgroundColor,
                              UIColor.secondarySystemBackgroundColor,
                              UIColor.tertiarySystemBackgroundColor,
                              UIColor.systemGroupedBackgroundColor,
                              UIColor.secondarySystemGroupedBackgroundColor,
                              UIColor.tertiarySystemGroupedBackgroundColor];
    
    // Fill colors
    self.fills = @[@"systemFillColor",
                   @"secondarySystemFillColor",
                   @"tertiarySystemFillColor",
                   @"quaternarySystemFillColor"];
    self.fillColors = @[UIColor.systemFillColor,
                        UIColor.secondarySystemFillColor,
                        UIColor.tertiarySystemFillColor,
                        UIColor.quaternarySystemFillColor];
    
    // System colors
    self.systems = @[@"systemRedColor",
                     @"systemGreenColor",
                     @"systemBlueColor",
                     @"systemOrangeColor",
                     @"systemYellowColor",
                     @"systemPinkColor",
                     @"systemPurpleColor",
                     @"systemTealColor",
                     @"systemIndigoColor"];
    self.systemColors = @[UIColor.systemRedColor,
                        UIColor.systemGreenColor,
                        UIColor.systemBlueColor,
                        UIColor.systemOrangeColor,
                        UIColor.systemYellowColor,
                        UIColor.systemPinkColor,
                        UIColor.systemPurpleColor,
                        UIColor.systemTealColor,
                        UIColor.systemIndigoColor];
    
    [self.tableViewArray addObject:self.foregrounds];
    [self.tableViewArray addObject:self.backgrounds];
    [self.tableViewArray addObject:self.fills];
    [self.tableViewArray addObject:self.systems];


    [self.tableViewColorArray addObject:self.foregroundColors];
    [self.tableViewColorArray addObject:self.backgroundColors];
    [self.tableViewColorArray addObject:self.fillColors];
    [self.tableViewColorArray addObject:self.systemColors];


    [self.view addSubview:self.tableView];
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
    return self.headArray[section];
}


- (UITableView *)tableView{
    if (!_tableView) {
        _tableView = [[UITableView alloc]initWithFrame:self.view.frame style:UITableViewStyleInsetGrouped];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        [_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"ID"];
        _tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
    }
    return _tableView;
}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return self.tableViewArray.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return [self.tableViewArray[section] count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"ID" forIndexPath:indexPath];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    NSString * num = [[NSString stringWithFormat:@"%ld",(long)indexPath.row] stringByAppendingString:@"  "];
    cell.textLabel.text  = [num stringByAppendingString:self.tableViewArray[indexPath.section][indexPath.row]];
    cell.textLabel.font = [UIFont systemFontOfSize:14];
    cell.backgroundColor = self.tableViewColorArray[indexPath.section][indexPath.row];
    return cell;
}

@end
